package com.cqc.slidingmenudmeo.activity;

import android.os.Bundle;

import com.cqc.slidingmenudmeo.R;
import com.cqc.slidingmenudmeo.fragment.BaseFragment;
import com.cqc.slidingmenudmeo.fragment.HomeFragment;
import com.cqc.slidingmenudmeo.fragment.LeftMenuFragment;
import com.cqc.slidingmenudmeo.fragment.RightMenuFragment;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainActivity extends SlidingFragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frame_content);
        setBehindContentView(R.layout.frame_menu_left);


        SlidingMenu menu = getSlidingMenu();
        menu.setMode(SlidingMenu.LEFT_RIGHT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//点击全屏后侧栏栏收回
        menu.setBehindWidthRes(R.dimen.behind_offset);
        menu.setShadowDrawable(R.drawable.shadow);//分割线图片
        menu.setShadowWidthRes(R.dimen.shadow_width);

//        menu.setShadowWidth(R.dimen.shadow_width);//错误：必须是具体的数值，而dimen里是 xdp
//        menu.setBehindOffset(R.dimen.behind_offset);//错误：必须是具体的数值，而dimen里是 xdp
//        menu.setBehindWidth(R.dimen.behind_width);//错误：必须是具体的数值，而dimen里是 xdp

        menu.setSecondaryMenu(R.layout.frame_menu_right);
        menu.setSecondaryShadowDrawable(R.drawable.shadow_secondary);//第二张分割线图片

        //替换左侧侧安栏
        LeftMenuFragment leftFragmetLeft = new LeftMenuFragment();
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_menu_left,leftFragmetLeft,"LeftMenuFragment")
                .commit();

        //替换右侧侧拉栏
        RightMenuFragment rightFragment = new RightMenuFragment();
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_menu_right,rightFragment,"RightMenuFragment")
                .commit();

        //替换内容页
        HomeFragment homeFragment = new HomeFragment();
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_content,homeFragment,"HomeFragment")
                .commit();
    }


    public void switchFragment(BaseFragment fragment){
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_content,fragment)
                .commit();
    }
}
